<!--
* description: 备件奖励单业务审核
* author: xiaochengzuan
* createdDate: 2021-1-22
-->

<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="true"
      :dynamic-is-init-table="true"
      :dynamic-api-style="'restful'"
      :callback-obj="callBackObj"
    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible.sync="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />
  </div>
</template>
<script>

import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'
import { api } from './api'
import { exportExcel } from '@/utils/exportExcel'

export default {
  name: 'BusinessAuditOfSparePartsRewardList',

  components: {
    OneTableTemplate,
    Edit: () => import('./edit')
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      callBackObj: {
        onCheckSelectChange: (sel) => {
          this.selectData = sel
        }
      },
      selectData: [],
      editRowData: {},
      // 网格查询API配置对象
      apiConfig: api.queryBonusBusiReviewPage,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'comKey3',
          type: '',
          size: 'small',
          name: '',
          position: 'right',
          clickEvent: () => {
            if (this.selectData.length) {
              this.editRowData = {}
              this.showEdit('pass')
            } else {
              this.$message('请先至少选择一条数据！')
            }

          },
          text: '通过',
          disabled: false
        },
        {
          compKey: 'btnKey3',
          type: '',
          size: 'small',
          clickEvent: () => {
            if (this.selectData.length) {
              this.editRowData = {}
              this.showEdit('reject')
            } else {
              this.$message('请先至少选择一条数据！')
            }
          },
          text: '驳回',
          name: '',
          position: 'right'
        //   fuzzySearch: true
        },
        {
          compKey: 'btnKey3',
          type: '',
          size: 'small',
          name: 'export',
          position: 'right',
          clickEvent: () => {
            exportExcel.call(this, api.exoprtBonusBusiReview.APIUrl)
          }, // 导出
          text: '导出'
        },
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'comKey1',
              labelName: '网点名称：',
              codeField: 'dlrCode',
              textField: 'dlrShortName',
              component: () => import('@/views/ve/planReport/components/multipleSearchInput'),
              type: 'inputText',
              isMust: true,
              dataToObject: {
                oFields: 'dlrCode,dlrShortName',
                // 控制弹窗页面 搜索 网格 元素
                tableComponents: [
                  {
                    compKey: 'compKey1',
                    labelName: '网点名称：',
                    codeField: 'dlrShortName',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  },
                  {
                    compKey: 'compKey2',
                    labelName: '网点编码：',
                    codeField: 'dlrCode',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  }
                ],
                tableCols: [
                  {
                    prop: 'dlrCode',
                    label: '网点编码'
                  },
                  {
                    prop: 'dlrShortName',
                    label: '网点名称'
                  }
                ],
                formField: {
                  dlrShortName: '',
                  dlrCode: ''
                },
                returnField: {
                  prop: 'dlrShortName',
                  label: '网点名称'
                },
                api: api.queryOrgDlrCodes
              },
              span: 6
            },
            {
              compKey: 'compKey2',
              labelName: '网点编码：',
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey3',
              labelName: '奖励种类: ',
              codeField: 'bonusTypeId',
              textField: 'bonusTypeName',
              component: () => import('@/components/org/commonSelect'),
              customObj: {
                listQuery: { },
                api: {
                  APIUrl: '/mp/e3sh/spareparts/finance/bonusOrderMakeService/queryBonusTypes.do',
                  ServiceCode: 'queryBonusTypes'
                },
                selectType: '1'
              },
              oFields: 'bonusTypeId,bonusTypeName',
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey4',
              labelName: '奖励项目：',
              codeField: 'bonusItemId',
              textField: 'bonusItemName',
              component: () => import('@/components/org/commonSelect'),
              oFields: 'bonusItemId,bonusItemName',
              customObj: {
                listQuery: { },
                api: {
                  APIUrl: '/mp/e3sh/spareparts/finance/bonusOrderMakeService/queryBonusItems.do',
                  ServiceCode: 'queryBonusItems'
                },
                selectType: '1'
              },
              type: 'dropdownList',
              // isMul: true,
              isMust: true,
              span: 6
            },
            // {
            //   compKey: 'compKey4',
            //   labelName: '所属期间：',
            //   codeField: 'bigAreaName3',
            //   component: () => import('@/components/org/datePicker/andtDatePicker'),
            //   type: 'andtDatePicker',
            //   isMul: false,
            //   isMust: false
            // },
            {
              compKey: 'compKey5',
              labelName: '奖励单号：',
              codeField: 'bonusOrderCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false,
              span: 6
            },
            // {
            //   compKey: 'compKey5',
            //   labelName: '审核状态：',
            //   codeField: 'bonusStatus',
            //   textField: 'bonusStatusCn',
            //   component: () => import('@/components/org/commonSelect'),
            //   customObj: {
            //     listQuery: { },
            //     api: { APIUrl: '/mp/e3sh/spareparts/finance/bonusOrderMakeService/queryBonusStatus.do' },
            //     selectType: '1'
            //   },
            //   type: 'dropdownList',
            //   // isMul: true,
            //   isMust: false,
            //   span: 6
            // }
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'releaseId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            // {
            //   prop: 'controlBtn1',
            //   label: '操作',
            //   minWidth: 180,
            //   isComponent: true,
            //   comps: [
            //     // {
            //     //   compKey: 'propKey1',
            //     //   labelName: '修改',
            //     //   component: () => import('@/components/org/linkButton'),
            //     //   clickEvent: (index) => this.edit(index)
            //     // }
            //   ]
            // },
            {
              prop: 'dlrCode',
              label: '网点编码',
              hidden: false
            //   alwaysHidden: true
            },
            {
              prop: 'dlrShortName',
              label: '网点名称'
            },
            {
              prop: 'bonusOrderCode',
              label: '奖励单号'
            },
            // {
            //   prop: 'bigAreaCode',
            //   label: '所属期间'
            // },
            {
              prop: 'bonusTypeName',
              label: '奖励种类'
            },
            {
              prop: 'bonusItemName',
              label: '奖励项目'
            },
            {
              prop: 'bonusAmount',
              label: '奖励金额'
            },
            {
              prop: 'creator',
              label: '创建人'
            },
            {
              prop: 'createdDate',
              label: '创建时间'
            },
            {
              prop: 'bonusStatusCn',
              label: '审核状态'
            },
            {
              prop: 'biReviewOpinions',
              label: '业务审核意见'
            },
            {
              prop: 'fiReviewOpinions',
              label: '财务审核意见'
            }

          ],

      // 表单查询数据
      formField: this.$utils.getFormField(this, {
        dlrCode: '',
        dlrShortName: '',
        bonusTypeId: '',
        bonusTypeName: '',
        bonusItemId: '',
        bonusItemName: '',
        bonusOrderCode: '',
        bonusStatus: '',
        bonusStatusCn: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },

  mounted() {
    // 列表查询
    this.queryTable(1)
  },

  methods: {
    // 编辑获取数据
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$utils.deepCopy(this.$refs['multipleTable'].list[index])
    },

  }
}
</script>
